function bvqxfile_clear(l)
% BVQXfile::<PRIVATE>::clear  - clears objects' memory for given handles

% Version:  v0.7f
% Build:    8110521
% Date:     Nov-05 2008, 9:00 PM CET
% Author:   Jochen Weber, SCAN Unit, Columbia University, NYC, NY, USA
% URL/Info: http://wiki.brainvoyager.com/BVQXtools

% global storage
global bvqxclup;
global bvqxcont;

try
    [rl{1:2}] = intersect(bvqxclup(2:end), l);
    rl = rl{2} + 1;
    clu = {bvqxcont(rl).H};
    for c = 1:numel(clu)
        if isfield(clu{c}, 'CleanUp') && ...
            iscell(clu{c}.CleanUp) && ...
           ~isempty(clu{c}.CleanUp)
            clus = clu{c}.CleanUp;
            for cluc = 1:numel(clus)
                if ischar(clus{cluc}) && ...
                   ~isempty(clus{cluc})
                    evalin('base', clus{cluc}(:)', '');
                end
            end
        end
    end
    bvqxcont(rl) = [];
    bvqxclup(rl) = [];
catch
    error( ...
        'BVQXfile:LookupError', ...
        'Error looking up/clearing objects.' ...
    );
end
